from django.db import models


# Create your models here.
# 小组与学生一对多
class Group(models.Model):
    name = models.CharField(verbose_name='小组名字',max_length=5)

    def __str__(self):
        return self.name


class Student(models.Model):
    name = models.CharField(verbose_name='学生名字',max_length=10)
    age = models.IntegerField(verbose_name='学生年龄')
    group = models.ForeignKey(to=Group,on_delete=models.CASCADE)


# 分类
class Category(models.Model):
    name = models.CharField(verbose_name="分类",max_length=100)

    def __str__(self):
        return self.name


class Article(models.Model):
    title = models.CharField(verbose_name='标题',max_length=100)
    vum = models.IntegerField(verbose_name='浏览量')
    content = models.TextField(verbose_name='内容')
    category = models.ForeignKey(to=Category,on_delete=models.CASCADE,related_name='artcles',default="")

    def __str__(self):
        return self.title


class Cate(models.Model):
    name = models.CharField(verbose_name="分类",max_length=100)

    def __str__(self):
        return self.name


class Title(models.Model):
    title = models.CharField(verbose_name='标题',max_length=100)
    vum = models.IntegerField(verbose_name='浏览量')
    content = models.TextField(verbose_name='内容')
    cate = models.ForeignKey(to=Cate,on_delete=models.CASCADE)

    def __str__(self):
        return self.title


class Sun(models.Model):
    name = models.CharField(verbose_name="分类", max_length=100)

    def __str__(self):
        return self.name

class After(models.Model):
    title = models.CharField(verbose_name='标题', max_length=100)
    vum = models.IntegerField(verbose_name='浏览量')
    content = models.TextField(verbose_name='内容')
    sun = models.ForeignKey(to=Sun, on_delete=models.CASCADE,related_name='after') # related_name 反向查找

    def __str__(self):
        return self.title


# DRF模型序列化验证
class User(models.Model):
    GENDERS = (
        (1,'男'),(2,'女')
    )
    name = models.CharField(max_length=10,verbose_name='名字')
    phone = models.CharField(max_length=11,verbose_name='手机号')
    gender = models.IntegerField(choices=GENDERS,verbose_name='性别')
    pwd = models.CharField(verbose_name='密码',max_length=64)





